<?php

namespace App\Admin\Renderable;


use App\Models\ForeignSpeakerCollection;
use App\Models\ForeignSpeakerCollectionPivot;
use App\Models\Speaker;
use Dcat\Admin\Support\LazyRenderable;
use Dcat\Admin\Widgets\Table;

class SpeakerCollectionTable extends LazyRenderable
{

    public function render()
    {
        $id = $this->id;

        $collection_list = ForeignSpeakerCollectionPivot::where('collection_id', $id)->get();

        $data = [];
        foreach ($collection_list as $key => $val) {
            $collection = $this->getCollectionInfo($val['collection_id']);
            $speaker = $this->getSpeakerInfo($val['speaker_id']);
            // $user = $this->getUserInfo($val['user_id']);
            $data[] = [
                $collection['name'],
                $speaker['name'] ?? '未找到讲者',
                $speaker['medical_category'] ?? '未找到讲者',
            ];
        }
        return Table::make(['合集名称', '讲者名称', '讲者领域'], $data);
    }

    protected function getCollectionInfo($id)
    {
        return ForeignSpeakerCollection::find($id);
    }

    protected function getSpeakerInfo($id)
    {
        return Speaker::find($id);
    }
}
